/**
 * Project Name: pcrdrive.com
 * Author: Micutaru Ciprian Marius
 * Date: 15:10 - 04/08/14 - 2014
 * Desc:
 */



$( document ).ready(function() {
	$(function() {

		$( ".form_content" ).dialog({
			autoOpen: false,
			width: 'auto',
			maxWidth: 800,
			height: 'auto',
			dialogClass: "test",
			modal: false,
			fluid: true,
			resizable: false,
			show: {
				effect: "clip",
				duration: 1000
			},
			hide: {
				effect: "fade",
				duration: 1000
			}
		});

		$( ".load_form" ).click(function() {
			$( ".form_content" ).dialog( "open" );
		});

		// on window resize run function
		$(window).resize(function () {
			fluidDialog();
		});

		// catch dialog if opened within a viewport smaller than the dialog width
		$(document).on("dialogopen", ".ui-dialog", function (event, ui) {
			fluidDialog();
		});

		function fluidDialog() {
			var $visible = $(".ui-dialog:visible");
			// each open dialog
			$visible.each(function () {
				var $this = $(this);
				var dialog = $this.find(".ui-dialog-content").data("ui-dialog");
				// if fluid option == true
				if (dialog.options.fluid) {
					var wWidth = $(window).width();
					// check window width against dialog width
					if (wWidth < (parseInt(dialog.options.maxWidth) + 50))  {
						// keep dialog from filling entire screen
						$this.css("max-width", "100%");
					} else {
						// fix maxWidth bug
						$this.css("max-width", dialog.options.maxWidth + "px");
					}
					//reposition dialog
					dialog.option("position", dialog.options.position);
				}
			});

		}

		$( ".specify_regions_content").hide();

		$( ".specify_regions" ).click(function() {
			$( ".specify_regions_content" ).toggle( "slow", function() {

			});

		});

		var $set_left_primer_content = $( ".set_left_primer_content");
		var $set_hybrid_content = $( ".set_hybrid_content");
		var $set_right_primer_content = $( ".set_right_primer_content");
		$set_left_primer_content.hide();
		$set_hybrid_content.hide();
		$set_right_primer_content.hide();

		$( ".set_left_primer" ).click(function() {
			if($(".set_left_primer").is(':checked'))
				$set_left_primer_content.show();
			else
				$set_left_primer_content.hide();
		});

		$( ".set_hybrid" ).click(function() {
			if($(".set_hybrid").is(':checked'))
				$set_hybrid_content.show();
			else
				$set_hybrid_content.hide();
		});

		$( ".set_right_primer" ).click(function() {
			if($(".set_right_primer").is(':checked'))
				$set_right_primer_content.show();
			else
				$set_right_primer_content.hide();
		});

	});
});